package com.loma.common.utils.util

import android.content.Context
import android.graphics.Color
import com.loma.common.R


fun Context.getStatusBarHeight(    ): Int {
    var statusBarHeight = 0
    val resourceId =  resources.getIdentifier("status_bar_height", "dimen", "android")
    if (resourceId > 0) {
        statusBarHeight =  resources.getDimensionPixelSize(resourceId)
    }
    return statusBarHeight
}


fun Context.isLightColor(color: Int): Boolean {
    val darkness: Double = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255
    return    darkness < 0.5
}

///** 获取状态栏高度 **/
//@SuppressLint("PrivateApi")
//fun Context.getStatusBarHeight(): Int {
//    val defaultHeightValue = 75
//    try {
//        val clazz = Class.forName("com.android.internal.R\$dimen")
//        val obj = clazz.newInstance()
//        val field = clazz.getField("status_bar_height")
//        field.let {
//            field.isAccessible = true
//            val x = field.get(obj)?.toString()?.let { it1 -> Integer.parseInt(it1) }
//            return if (x != null) resources.getDimensionPixelSize(x) else defaultHeightValue
//        }
//    } catch (e: Exception) {
//        e.printStackTrace()
//    }
//    return defaultHeightValue
//}

/** 获取ActionBar的高度 **/
  fun Context.actionBarHeight() = resources.getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material)


/**
 * 获取屏幕的宽高
 *
 * @param context
 * @return
 */
fun Context.getScreenSize( ): IntArray {
    val displayMetrics = resources.displayMetrics
    return intArrayOf(displayMetrics.widthPixels, displayMetrics.heightPixels)
}

fun Context.getScreenHeight( ): Int {
    return getScreenSize()[1]
}

fun Context.getScreenWidth(context: Context): Int {
    return getScreenSize()[0]
}

